home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / winsock-.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  30.5 KB  |  891 lines

  1. /*
  2.  *  This is a local, modified copy of WINSOCK.H, which does not #include the WINDOWS.H
  3.  *  file.  This is to prevent clashes between things defined there and in the WAIS code.
  4.  *  Author: Chris Adie.
  5.  */
  6.  
  7. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  8.  *
  9.  * This header file corresponds to version 1.1 of the Windows Sockets specification.
  10.  *
  11.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  12.  * of the University of California.  All rights reserved.  The
  13.  * Berkeley Software License Agreement specifies the terms and
  14.  * conditions for redistribution.
  15.  *
  16.  * Change log:
  17.  *
  18.  * Fri Apr 23 16:31:01 1993  Mark Towfiq  (towfiq@Microdyne.COM)
  19.  *  New version from David Treadwell which adds extern "C" around
  20.  *  __WSAFDIsSet() and removes "const" from buf param of
  21.  *  WSAAsyncGetHostByAddr().  Added change log.
  22.  *
  23.  * Sat May 15 10:55:00 1993 David Treadwell (davidtr@microsoft.com)
  24.  *  Fix the IN_CLASSC macro to account for class-D multicasts.
  25.  *  Add AF_IPX == AF_NS.
  26.  *
  27.  */
  28.  
  29. #ifndef _WINSOCKAPI_
  30. #define _WINSOCKAPI_
  31.  
  32. /*
  33.  * Pull in WINDOWS.H if necessary
  34.  */
  35. //#ifndef _INC_WINDOWS
  36. //#include <windows.h>
  37. //#endif
  38.  
  39. /* Some things from WINDOWS.H which are needed: */
  40. #define PASCAL
  41. #define FAR
  42. #define WINAPI __stdcall
  43. /* typedef unsigned short WORD; Can't use this cos WORD means something else to WAIS */
  44. typedef unsigned long DWORD;
  45. typedef int BOOL;
  46. typedef void *HANDLE;
  47. typedef HANDLE HWND;
  48. typedef int (FAR WINAPI *FARPROC)();
  49.  
  50. /*
  51.  * Basic system type definitions, taken from the BSD file sys/types.h.
  52.  */
  53. typedef unsigned char   u_char;
  54. typedef unsigned short  u_short;
  55. typedef unsigned int    u_int;
  56. typedef unsigned long   u_long;
  57.  
  58. /*
  59.  * The new type to be used in all
  60.  * instances which refer to sockets.
  61.  */
  62. typedef u_int           SOCKET;
  63.  
  64. /*
  65.  * Select uses arrays of SOCKETs.  These macros manipulate such
  66.  * arrays.  FD_SETSIZE may be defined by the user before including
  67.  * this file, but the default here should be >= 64.
  68.  *
  69.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  70.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  71.  */
  72. #ifndef FD_SETSIZE
  73. #define FD_SETSIZE      64
  74. #endif /* FD_SETSIZE */
  75.  
  76. typedef struct fd_set {
  77.         u_int   fd_count;               /* how many are SET? */
  78.         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  79. } fd_set;
  80.  
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif
  84.  
  85. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  86.  
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90.  
  91.  
  92. #define FD_CLR(fd, set) do { \
  93.     u_int __i; \
  94.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  95.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  96.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  97.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  98.                     ((fd_set FAR *)(set))->fd_array[__i+1]; \
  99.                 __i++; \
  100.             } \
  101.             ((fd_set FAR *)(set))->fd_count--; \
  102.             break; \
  103.         } \
  104.     } \
  105. } while(0)
  106.  
  107. #define FD_SET(fd, set) do { \
  108.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  109.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=fd;\
  110. } while(0)
  111.  
  112. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  113.  
  114. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
  115.  
  116. /*
  117.  * Structure used in select() call, taken from the BSD file sys/time.h.
  118.  */
  119. struct timeval {
  120.         long    tv_sec;         /* seconds */
  121.         long    tv_usec;        /* and microseconds */
  122. };
  123.  
  124. /*
  125.  * Operations on timevals.
  126.  *
  127.  * NB: timercmp does not work for >= or <=.
  128.  */
  129. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  130. #define timercmp(tvp, uvp, cmp) \
  131.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  132.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  133. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  134.  
  135. /*
  136.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  137.  *
  138.  *
  139.  * Ioctl's have the command encoded in the lower word,
  140.  * and the size of any in or out parameters in the upper
  141.  * word.  The high 2 bits of the upper word are used
  142.  * to encode the in/out status of the parameter; for now
  143.  * we restrict parameters to at most 128 bytes.
  144.  */
  145. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  146. #define IOC_VOID        0x20000000      /* no parameters */
  147. #define IOC_OUT         0x40000000      /* copy out parameters */
  148. #define IOC_IN          0x80000000      /* copy in parameters */
  149. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  150.                                         /* 0x20000000 distinguishes new &
  151.                                            old ioctl's */
  152. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  153.  
  154. #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  155.  
  156. #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  157.  
  158. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  159. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  160. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  161.  
  162. /* Socket I/O Controls */
  163. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  164. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  165. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  166. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  167. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  168.  
  169. /*
  170.  * Structures returned by network data base library, taken from the
  171.  * BSD file netdb.h.  All addresses are supplied in host order, and
  172.  * returned in network order (suitable for use in system calls).
  173.  */
  174.  
  175. struct  hostent {
  176.         char    FAR * h_name;           /* official name of host */
  177.         char    FAR * FAR * h_aliases;  /* alias list */
  178.         short   h_addrtype;             /* host address type */
  179.         short   h_length;               /* length of address */
  180.         char    FAR * FAR * h_addr_list; /* list of addresses */
  181. #define h_addr  h_addr_list[0]          /* address, for backward compat */
  182. };
  183.  
  184. /*
  185.  * It is assumed here that a network number
  186.  * fits in 32 bits.
  187.  */
  188. struct  netent {
  189.         char    FAR * n_name;           /* official name of net */
  190.         char    FAR * FAR * n_aliases;  /* alias list */
  191.         short   n_addrtype;             /* net address type */
  192.         u_long  n_net;                  /* network # */
  193. };
  194.  
  195. struct  servent {
  196.         char    FAR * s_name;           /* official service name */
  197.         char    FAR * FAR * s_aliases;  /* alias list */
  198.         short   s_port;                 /* port # */
  199.         char    FAR * s_proto;          /* protocol to use */
  200. };
  201.  
  202. struct  protoent {
  203.         char    FAR * p_name;           /* official protocol name */
  204.         char    FAR * FAR * p_aliases;  /* alias list */
  205.         short   p_proto;                /* protocol # */
  206. };
  207.  
  208. /*
  209.  * Constants and structures defined by the internet system,
  210.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  211.  */
  212.  
  213. /*
  214.  * Protocols
  215.  */
  216. #define IPPROTO_IP              0               /* dummy for IP */
  217. #define IPPROTO_ICMP            1               /* control message protocol */
  218. #define IPPROTO_GGP             2               /* gateway^2 (deprecated) */
  219. #define IPPROTO_TCP             6               /* tcp */
  220. #define IPPROTO_PUP             12              /* pup */
  221. #define IPPROTO_UDP             17              /* user datagram protocol */
  222. #define IPPROTO_IDP             22              /* xns idp */
  223. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  224.  
  225. #define IPPROTO_RAW             255             /* raw IP packet */
  226. #define IPPROTO_MAX             256
  227.  
  228. /*
  229.  * Port/socket numbers: network standard functions
  230.  */
  231. #define IPPORT_ECHO             7
  232. #define IPPORT_DISCARD          9
  233. #define IPPORT_SYSTAT           11
  234. #define IPPORT_DAYTIME          13
  235. #define IPPORT_NETSTAT          15
  236. #define IPPORT_FTP              21
  237. #define IPPORT_TELNET           23
  238. #define IPPORT_SMTP             25
  239. #define IPPORT_TIMESERVER       37
  240. #define IPPORT_NAMESERVER       42
  241. #define IPPORT_WHOIS            43
  242. #define IPPORT_MTP              57
  243.  
  244. /*
  245.  * Port/socket numbers: host specific functions
  246.  */
  247. #define IPPORT_TFTP             69
  248. #define IPPORT_RJE              77
  249. #define IPPORT_FINGER           79
  250. #define IPPORT_TTYLINK          87
  251. #define IPPORT_SUPDUP           95
  252.  
  253. /*
  254.  * UNIX TCP sockets
  255.  */
  256. #define IPPORT_EXECSERVER       512
  257. #define IPPORT_LOGINSERVER      513
  258. #define IPPORT_CMDSERVER        514
  259. #define IPPORT_EFSSERVER        520
  260.  
  261. /*
  262.  * UNIX UDP sockets
  263.  */
  264. #define IPPORT_BIFFUDP          512
  265. #define IPPORT_WHOSERVER        513
  266. #define IPPORT_ROUTESERVER      520
  267.                                         /* 520+1 also used */
  268.  
  269. /*
  270.  * Ports < IPPORT_RESERVED are reserved for
  271.  * privileged processes (e.g. root).
  272.  */
  273. #define IPPORT_RESERVED         1024
  274.  
  275. /*
  276.  * Link numbers
  277.  */
  278. #define IMPLINK_IP              155
  279. #define IMPLINK_LOWEXPER        156
  280. #define IMPLINK_HIGHEXPER       158
  281.  
  282. /*
  283.  * Internet address (old style... should be updated)
  284.  */
  285. struct in_addr {
  286.         union {
  287.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  288.                 struct { u_short s_w1,s_w2; } S_un_w;
  289.                 u_long S_addr;
  290.         } S_un;
  291. #define s_addr  S_un.S_addr
  292.                                 /* can be used for most tcp & ip code */
  293. #define s_host  S_un.S_un_b.s_b2
  294.                                 /* host on imp */
  295. #define s_net   S_un.S_un_b.s_b1
  296.                                 /* network */
  297. #define s_imp   S_un.S_un_w.s_w2
  298.                                 /* imp */
  299. #define s_impno S_un.S_un_b.s_b4
  300.                                 /* imp # */
  301. #define s_lh    S_un.S_un_b.s_b3
  302.                                 /* logical host */
  303. };
  304.  
  305. /*
  306.  * Definitions of bits in internet address integers.
  307.  * On subnets, the decomposition of addresses to host and net parts
  308.  * is done according to subnet mask, not the masks here.
  309.  */
  310. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  311. #define IN_CLASSA_NET           0xff000000
  312. #define IN_CLASSA_NSHIFT        24
  313. #define IN_CLASSA_HOST          0x00ffffff
  314. #define IN_CLASSA_MAX           128
  315.  
  316. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  317. #define IN_CLASSB_NET           0xffff0000
  318. #define IN_CLASSB_NSHIFT        16
  319. #define IN_CLASSB_HOST          0x0000ffff
  320. #define IN_CLASSB_MAX           65536
  321.  
  322. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
  323. #define IN_CLASSC_NET           0xffffff00
  324. #define IN_CLASSC_NSHIFT        8
  325. #define IN_CLASSC_HOST          0x000000ff
  326.  
  327. #define INADDR_ANY              (u_long)0x00000000
  328. #define INADDR_LOOPBACK         0x7f000001
  329. #define INADDR_BROADCAST        (u_long)0xffffffff    
  330. #define INADDR_NONE             0xffffffff
  331.  
  332. /*
  333.  * Socket address, internet style.
  334.  */
  335. struct sockaddr_in {
  336.         short   sin_family;
  337.         u_short sin_port;
  338.         struct  in_addr sin_addr;
  339.         char    sin_zero[8];
  340. };
  341.  
  342. #define WSADESCRIPTION_LEN      256
  343. #define WSASYS_STATUS_LEN       128
  344.  
  345. typedef struct WSAData {
  346.         unsigned short /*WORD*/ wVersion;
  347.         unsigned short /*WORD*/ wHighVersion;
  348.         char                    szDescription[WSADESCRIPTION_LEN+1];
  349.         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
  350.         unsigned short          iMaxSockets;
  351.         unsigned short          iMaxUdpDg;
  352.         char FAR *              lpVendorInfo;
  353. } WSADATA;
  354.  
  355. typedef WSADATA FAR *LPWSADATA;
  356.  
  357. /*
  358.  * Options for use with [gs]etsockopt at the IP level.
  359.  */
  360. #define IP_OPTIONS      1               /* set/get IP per-packet options */
  361.  
  362. /*
  363.  * Definitions related to sockets: types, address families, options,
  364.  * taken from the BSD file sys/socket.h.
  365.  */
  366.  
  367. /*
  368.  * This is used instead of -1, since the
  369.  * SOCKET type is unsigned.
  370.  */
  371. #define INVALID_SOCKET  (SOCKET)(~0)
  372. #define SOCKET_ERROR            (-1)
  373.  
  374. /*
  375.  * Types
  376.  */
  377. #define SOCK_STREAM     1               /* stream socket */
  378. #define SOCK_DGRAM      2               /* datagram socket */
  379. #define SOCK_RAW        3               /* raw-protocol interface */
  380. #define SOCK_RDM        4               /* reliably-delivered message */
  381. #define SOCK_SEQPACKET  5               /* sequenced packet stream */
  382.  
  383. /*
  384.  * Option flags per-socket.
  385.  */
  386. #define SO_DEBUG        0x0001          /* turn on debugging info recording */
  387. #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
  388. #define SO_REUSEADDR    0x0004          /* allow local address reuse */
  389. #define SO_KEEPALIVE    0x0008          /* keep connections alive */
  390. #define SO_DONTROUTE    0x0010          /* just use interface addresses */
  391. #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
  392. #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
  393. #define SO_LINGER       0x0080          /* linger on close if data present */
  394. #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
  395.  
  396. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  397.  
  398. /*
  399.  * Additional options.
  400.  */
  401. #define SO_SNDBUF       0x1001          /* send buffer size */
  402. #define SO_RCVBUF       0x1002          /* receive buffer size */
  403. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  404. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  405. #define SO_SNDTIMEO     0x1005          /* send timeout */
  406. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  407. #define SO_ERROR        0x1007          /* get error status and clear */
  408. #define SO_TYPE         0x1008          /* get socket type */
  409.  
  410. /*
  411.  * Options for connect and disconnect data and options.  Used only by
  412.  * non-TCP/IP transports such as DECNet, OSI TP4, etc.
  413.  */
  414. #define SO_CONNDATA     0x7000
  415. #define SO_CONNOPT      0x7001
  416. #define SO_DISCDATA     0x7002
  417. #define SO_DISCOPT      0x7003
  418. #define SO_CONNDATALEN  0x7004
  419. #define SO_CONNOPTLEN   0x7005
  420. #define SO_DISCDATALEN  0x7006
  421. #define SO_DISCOPTLEN   0x7007
  422.  
  423. /*
  424.  * TCP options.
  425.  */
  426. #define TCP_NODELAY     0x0001
  427.  
  428. /*
  429.  * Address families.
  430.  */
  431. #define AF_UNSPEC       0               /* unspecified */
  432. #define AF_UNIX         1               /* local to host (pipes, portals) */
  433. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  434. #define AF_IMPLINK      3               /* arpanet imp addresses */
  435. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  436. #define AF_CHAOS        5               /* mit CHAOS protocols */
  437. #define AF_IPX          6               /* IPX and SPX */
  438. #define AF_NS           6               /* XEROX NS protocols */
  439. #define AF_ISO          7               /* ISO protocols */
  440. #define AF_OSI          AF_ISO          /* OSI is ISO */
  441. #define AF_ECMA         8               /* european computer manufacturers */
  442. #define AF_DATAKIT      9               /* datakit protocols */
  443. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  444. #define AF_SNA          11              /* IBM SNA */
  445. #define AF_DECnet       12              /* DECnet */
  446. #define AF_DLI          13              /* Direct data link interface */
  447. #define AF_LAT          14              /* LAT */
  448. #define AF_HYLINK       15              /* NSC Hyperchannel */
  449. #define AF_APPLETALK    16              /* AppleTalk */
  450. #define AF_NETBIOS      17              /* NetBios-style addresses */
  451.  
  452. #define AF_MAX          18
  453.  
  454. /*
  455.  * Structure used by kernel to store most
  456.  * addresses.
  457.  */
  458. struct sockaddr {
  459.         u_short sa_family;              /* address family */
  460.         char    sa_data[14];            /* up to 14 bytes of direct address */
  461. };
  462.  
  463. /*
  464.  * Structure used by kernel to pass protocol
  465.  * information in raw sockets.
  466.  */
  467. struct sockproto {
  468.         u_short sp_family;              /* address family */
  469.         u_short sp_protocol;            /* protocol */
  470. };
  471.  
  472. /*
  473.  * Protocol families, same as address families for now.
  474.  */
  475. #define PF_UNSPEC       AF_UNSPEC
  476. #define PF_UNIX         AF_UNIX
  477. #define PF_INET         AF_INET
  478. #define PF_IMPLINK      AF_IMPLINK
  479. #define PF_PUP          AF_PUP
  480. #define PF_CHAOS        AF_CHAOS
  481. #define PF_NS           AF_NS
  482. #define PF_IPX          AF_IPX
  483. #define PF_ISO          AF_ISO
  484. #define PF_OSI          AF_OSI
  485. #define PF_ECMA         AF_ECMA
  486. #define PF_DATAKIT      AF_DATAKIT
  487. #define PF_CCITT        AF_CCITT
  488. #define PF_SNA          AF_SNA
  489. #define PF_DECnet       AF_DECnet
  490. #define PF_DLI          AF_DLI
  491. #define PF_LAT          AF_LAT
  492. #define PF_HYLINK       AF_HYLINK
  493. #define PF_APPLETALK    AF_APPLETALK
  494.  
  495. #define PF_MAX          AF_MAX
  496.  
  497. /*
  498.  * Structure used for manipulating linger option.
  499.  */
  500. struct  linger {
  501.         u_short l_onoff;                /* option on/off */
  502.         u_short l_linger;               /* linger time */
  503. };
  504.  
  505. /*
  506.  * Level number for (get/set)sockopt() to apply to socket itself.
  507.  */
  508. #define SOL_SOCKET      0xffff          /* options for socket level */
  509.  
  510. /*
  511.  * Maximum queue length specifiable by listen.
  512.  */
  513. #define SOMAXCONN       5
  514.  
  515. #define MSG_OOB         0x1             /* process out-of-band data */
  516. #define MSG_PEEK        0x2             /* peek at incoming message */
  517. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  518.  
  519. #define MSG_MAXIOVLEN   16
  520.  
  521. #define MSG_PARTIAL     0x8000          /* partial send or recv for message xport */
  522.  
  523. /*
  524.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  525.  */
  526. #define MAXGETHOSTSTRUCT        1024
  527.  
  528. /*
  529.  * Define flags to be used with the WSAAsyncSelect() call.
  530.  */
  531. #define FD_READ         0x01
  532. #define FD_WRITE        0x02
  533. #define FD_OOB          0x04
  534. #define FD_ACCEPT       0x08
  535. #define FD_CONNECT      0x10
  536. #define FD_CLOSE        0x20
  537.  
  538. /*
  539.  * All Windows Sockets error constants are biased by WSABASEERR from
  540.  * the "normal"
  541.  */
  542. #define WSABASEERR              10000
  543. /*
  544.  * Windows Sockets definitions of regular Microsoft C error constants
  545.  */
  546. #define WSAEINTR                (WSABASEERR+4)
  547. #define WSAEBADF                (WSABASEERR+9)
  548. #define WSAEACCES               (WSABASEERR+13)
  549. #define WSAEFAULT               (WSABASEERR+14)
  550. #define WSAEINVAL               (WSABASEERR+22)
  551. #define WSAEMFILE               (WSABASEERR+24)
  552.  
  553. /*
  554.  * Windows Sockets definitions of regular Berkeley error constants
  555.  */
  556. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  557. #define WSAEINPROGRESS          (WSABASEERR+36)
  558. #define WSAEALREADY             (WSABASEERR+37)
  559. #define WSAENOTSOCK             (WSABASEERR+38)
  560. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  561. #define WSAEMSGSIZE             (WSABASEERR+40)
  562. #define WSAEPROTOTYPE           (WSABASEERR+41)
  563. #define WSAENOPROTOOPT          (WSABASEERR+42)
  564. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  565. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  566. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  567. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  568. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  569. #define WSAEADDRINUSE           (WSABASEERR+48)
  570. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  571. #define WSAENETDOWN             (WSABASEERR+50)
  572. #define WSAENETUNREACH          (WSABASEERR+51)
  573. #define WSAENETRESET            (WSABASEERR+52)
  574. #define WSAECONNABORTED         (WSABASEERR+53)
  575. #define WSAECONNRESET           (WSABASEERR+54)
  576. #define WSAENOBUFS              (WSABASEERR+55)
  577. #define WSAEISCONN              (WSABASEERR+56)
  578. #define WSAENOTCONN             (WSABASEERR+57)
  579. #define WSAESHUTDOWN            (WSABASEERR+58)
  580. #define WSAETOOMANYREFS         (WSABASEERR+59)
  581. #define WSAETIMEDOUT            (WSABASEERR+60)
  582. #define WSAECONNREFUSED         (WSABASEERR+61)
  583. #define WSAELOOP                (WSABASEERR+62)
  584. #define WSAENAMETOOLONG         (WSABASEERR+63)
  585. #define WSAEHOSTDOWN            (WSABASEERR+64)
  586. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  587. #define WSAENOTEMPTY            (WSABASEERR+66)
  588. #define WSAEPROCLIM             (WSABASEERR+67)
  589. #define WSAEUSERS               (WSABASEERR+68)
  590. #define WSAEDQUOT               (WSABASEERR+69)
  591. #define WSAESTALE               (WSABASEERR+70)
  592. #define WSAEREMOTE              (WSABASEERR+71)
  593.  
  594. #define WSAEDISCON              (WSABASEERR+101)
  595.  
  596. /*
  597.  * Extended Windows Sockets error constant definitions
  598.  */
  599. #define WSASYSNOTREADY          (WSABASEERR+91)
  600. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  601. #define WSANOTINITIALISED       (WSABASEERR+93)
  602.  
  603. /*
  604.  * Error return codes from gethostbyname() and gethostbyaddr()
  605.  * (when using the resolver). Note that these errors are
  606.  * retrieved via WSAGetLastError() and must therefore follow
  607.  * the rules for avoiding clashes with error numbers from
  608.  * specific implementations or language run-time systems.
  609.  * For this reason the codes are based at WSABASEERR+1001.
  610.  * Note also that [WSA]NO_ADDRESS is defined only for
  611.  * compatibility purposes.
  612.  */
  613.  
  614. #define h_errno         WSAGetLastError()
  615.  
  616. /* Authoritative Answer: Host not found */
  617. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  618. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  619.  
  620. /* Non-Authoritative: Host not found, or SERVERFAIL */
  621. #define WSATRY_AGAIN            (WSABASEERR+1002)
  622. #define TRY_AGAIN               WSATRY_AGAIN
  623.  
  624. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  625. #define WSANO_RECOVERY          (WSABASEERR+1003)
  626. #define NO_RECOVERY             WSANO_RECOVERY
  627.  
  628. /* Valid name, no data record of requested type */
  629. #define WSANO_DATA              (WSABASEERR+1004)
  630. #define NO_DATA                 WSANO_DATA
  631.  
  632. /* no address, look for MX record */
  633. #define WSANO_ADDRESS           WSANO_DATA
  634. #define NO_ADDRESS              WSANO_ADDRESS
  635.  
  636. /*
  637.  * Windows Sockets errors redefined as regular Berkeley error constants.
  638.  * These are commented out in Windows NT to avoid conflicts with errno.h.
  639.  * Use the WSA constants instead.
  640.  */
  641. #if 0
  642. #define EWOULDBLOCK             WSAEWOULDBLOCK
  643. #define EINPROGRESS             WSAEINPROGRESS
  644. #define EALREADY                WSAEALREADY
  645. #define ENOTSOCK                WSAENOTSOCK
  646. #define EDESTADDRREQ            WSAEDESTADDRREQ
  647. #define EMSGSIZE                WSAEMSGSIZE
  648. #define EPROTOTYPE              WSAEPROTOTYPE
  649. #define ENOPROTOOPT             WSAENOPROTOOPT
  650. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  651. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  652. #define EOPNOTSUPP              WSAEOPNOTSUPP
  653. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  654. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  655. #define EADDRINUSE              WSAEADDRINUSE
  656. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  657. #define ENETDOWN                WSAENETDOWN
  658. #define ENETUNREACH             WSAENETUNREACH
  659. #define ENETRESET               WSAENETRESET
  660. #define ECONNABORTED            WSAECONNABORTED
  661. #define ECONNRESET              WSAECONNRESET
  662. #define ENOBUFS                 WSAENOBUFS
  663. #define EISCONN                 WSAEISCONN
  664. #define ENOTCONN                WSAENOTCONN
  665. #define ESHUTDOWN               WSAESHUTDOWN
  666. #define ETOOMANYREFS            WSAETOOMANYREFS
  667. #define ETIMEDOUT               WSAETIMEDOUT
  668. #define ECONNREFUSED            WSAECONNREFUSED
  669. #define ELOOP                   WSAELOOP
  670. #define ENAMETOOLONG            WSAENAMETOOLONG
  671. #define EHOSTDOWN               WSAEHOSTDOWN
  672. #define EHOSTUNREACH            WSAEHOSTUNREACH
  673. #define ENOTEMPTY               WSAENOTEMPTY
  674. #define EPROCLIM                WSAEPROCLIM
  675. #define EUSERS                  WSAEUSERS
  676. #define EDQUOT                  WSAEDQUOT
  677. #define ESTALE                  WSAESTALE
  678. #define EREMOTE                 WSAEREMOTE
  679. #endif
  680.  
  681. /* Socket function prototypes */
  682.  
  683. #ifdef __cplusplus
  684. extern "C" {
  685. #endif
  686.  
  687. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  688.                           int FAR *addrlen);
  689.  
  690. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  691.  
  692. int PASCAL FAR closesocket (SOCKET s);
  693.  
  694. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  695.  
  696. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  697.  
  698. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  699.                             int FAR * namelen);
  700.  
  701. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  702.                             int FAR * namelen);
  703.  
  704. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  705.                            char FAR * optval, int FAR *optlen);
  706.  
  707. u_long PASCAL FAR htonl (u_long hostlong);
  708.  
  709. u_short PASCAL FAR htons (u_short hostshort);
  710.  
  711. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  712.  
  713. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  714.  
  715. int PASCAL FAR listen (SOCKET s, int backlog);
  716.  
  717. u_long PASCAL FAR ntohl (u_long netlong);
  718.  
  719. u_short PASCAL FAR ntohs (u_short netshort);
  720.  
  721. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  722.  
  723. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  724.                          struct sockaddr FAR *from, int FAR * fromlen);
  725.  
  726. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  727.                        fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  728.  
  729. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  730.  
  731. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  732.                        const struct sockaddr FAR *to, int tolen);
  733.  
  734. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  735.                            const char FAR * optval, int optlen);
  736.  
  737. int PASCAL FAR shutdown (SOCKET s, int how);
  738.  
  739. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  740.  
  741. /* Database function prototypes */
  742.  
  743. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  744.                                               int len, int type);
  745.  
  746. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  747.  
  748. int PASCAL FAR gethostname (char FAR * name, int namelen);
  749.  
  750. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  751.  
  752. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  753.                                               const char FAR * proto);
  754.  
  755. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  756.  
  757. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  758.  
  759. /* Microsoft Windows Extension function prototypes */
  760.  
  761. int PASCAL FAR WSAStartup(unsigned short /*WORD*/ wVersionRequired, LPWSADATA lpWSAData);
  762.  
  763. int PASCAL FAR WSACleanup(void);
  764.  
  765. void PASCAL FAR WSASetLastError(int iError);
  766.  
  767. int PASCAL FAR WSAGetLastError(void);
  768.  
  769. BOOL PASCAL FAR WSAIsBlocking(void);
  770.  
  771. int PASCAL FAR WSAUnhookBlockingHook(void);
  772.  
  773. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  774.  
  775. int PASCAL FAR WSACancelBlockingCall(void);
  776.  
  777. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  778.                                         const char FAR * name, 
  779.                                         const char FAR * proto,
  780.                                         char FAR * buf, int buflen);
  781.  
  782. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  783.                                         const char FAR * proto, char FAR * buf,
  784.                                         int buflen);
  785.  
  786. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  787.                                          const char FAR * name, char FAR * buf,
  788.                                          int buflen);
  789.  
  790. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  791.                                            int number, char FAR * buf,
  792.                                            int buflen);
  793.  
  794. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  795.                                         const char FAR * name, char FAR * buf,
  796.                                         int buflen);
  797.  
  798. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  799.                                         const char FAR * addr, int len, int type,
  800.                                         char FAR * buf, int buflen);
  801.  
  802. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  803.  
  804. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  805.                                long lEvent);
  806.  
  807. int PASCAL FAR WSARecvEx (SOCKET s, char FAR * buf, int len, int *flags);
  808.  
  809. #ifdef __cplusplus
  810. }
  811. #endif
  812.  
  813. /* Microsoft Windows Extended data types */
  814. typedef struct sockaddr SOCKADDR;
  815. typedef struct sockaddr *PSOCKADDR;
  816. typedef struct sockaddr FAR *LPSOCKADDR;
  817.  
  818. typedef struct sockaddr_in SOCKADDR_IN;
  819. typedef struct sockaddr_in *PSOCKADDR_IN;
  820. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  821.  
  822. typedef struct linger LINGER;
  823. typedef struct linger *PLINGER;
  824. typedef struct linger FAR *LPLINGER;
  825.  
  826. typedef struct in_addr IN_ADDR;
  827. typedef struct in_addr *PIN_ADDR;
  828. typedef struct in_addr FAR *LPIN_ADDR;
  829.  
  830. typedef struct fd_set FD_SET;
  831. typedef struct fd_set *PFD_SET;
  832. typedef struct fd_set FAR *LPFD_SET;
  833.  
  834. typedef struct hostent HOSTENT;
  835. typedef struct hostent *PHOSTENT;
  836. typedef struct hostent FAR *LPHOSTENT;
  837.  
  838. typedef struct servent SERVENT;
  839. typedef struct servent *PSERVENT;
  840. typedef struct servent FAR *LPSERVENT;
  841.  
  842. typedef struct protoent PROTOENT;
  843. typedef struct protoent *PPROTOENT;
  844. typedef struct protoent FAR *LPPROTOENT;
  845.  
  846. typedef struct timeval TIMEVAL;
  847. typedef struct timeval *PTIMEVAL;
  848. typedef struct timeval FAR *LPTIMEVAL;
  849.  
  850. /*
  851.  * Windows message parameter composition and decomposition
  852.  * macros.
  853.  *
  854.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  855.  * when constructing the response to a WSAAsyncGetXByY() routine.
  856.  */
  857. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  858. /*
  859.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  860.  * when constructing the response to WSAAsyncSelect().
  861.  */
  862. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  863. /*
  864.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  865.  * to extract the buffer length from the lParam in the response
  866.  * to a WSAGetXByY().
  867.  */
  868. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  869. /*
  870.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  871.  * to extract the error code from the lParam in the response
  872.  * to a WSAGetXByY().
  873.  */
  874. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  875. /*
  876.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  877.  * to extract the event code from the lParam in the response
  878.  * to a WSAAsyncSelect().
  879.  */
  880. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  881. /*
  882.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  883.  * to extract the error code from the lParam in the response
  884.  * to a WSAAsyncSelect().
  885.  */
  886. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  887.  
  888. #endif  /* _WINSOCKAPI_ */
  889.  
  890.  
  891.